// custom-tab-bar/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {},
  /**
   * 组件的初始数据
   */
  data: {
    identity: '',
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#3cc51f",
    touristTabbarList: [
      {
        "pagePath": "../home/home",
        "text": "首页",
        "iconPath": "/static/首页.png",
        "selectedIconPath": "/static/首页-active.png"
      },
      {
        "pagePath": "../my/my",
        "text": "我的",
        "iconPath": "/static/我的.png",
        "selectedIconPath": "/static/我的-active.png"
      }
    ],
    elderTabbarList: [
      {
        "pagePath": "../home/home",
        "text": "首页",
        "iconPath": "/static/首页.png",
        "selectedIconPath": "/static/首页-active.png"
      },
      {
        "pagePath": "../services/services",
        "text": "服务",
        "iconPath": "/static/服务.png",
        "selectedIconPath": "/static/服务-active.png"
      },
      {
        "pagePath": "../updates/updates",
        "text": "动态",
        "iconPath": "/static/发现.png",
        "selectedIconPath": "/static/发现-active.png"
      },
      {
        "pagePath": "../my/my",
        "text": "我的",
        "iconPath": "/static/我的.png",
        "selectedIconPath": "/static/我的-active.png"
      }
    ],
    familyTabarList: [
      {
        "pagePath": "../home/home",
        "text": "首页",
        "iconPath": "/static/首页.png",
        "selectedIconPath": "/static/首页-active.png"
      },
      {
        "pagePath": "../services/services",
        "text": "服务",
        "iconPath": "/static/服务.png",
        "selectedIconPath": "/static/服务-active.png"
      },
      {
        "pagePath": "../hospital/hospital",
        "text": "院方在线",
        "iconPath": "/static/院方在线.png",
        "selectedIconPath": "/static/院方在线-active.png"
      },
      {
        "pagePath": "../my/my",
        "text": "我的",
        "iconPath": "/static/我的.png",
        "selectedIconPath": "/static/我的-active.png"
      }
    ],
    list: []
  },
  lifetimes: {
    attached: function () {
      const identity = wx.getStorageSync('identity');
      let list = [];
      if (identity === '老人') {
        list = this.data.elderTabbarList;
      } else if (identity === '游客') {
        list = this.data.touristTabbarList;
      } else {
        list = this.data.familyTabarList;
      }
      this.setData({ list });
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    switchTab(e) {
      const { path, index } = e.currentTarget.dataset;
      wx.switchTab({
        url: path,
        success: () => {
          this.setData({ selected: index });
        }
      });
    }
  }
});